home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / LDB171.ARJ / EXAMP402.CPP < prev    next >
Text File  |  1992-05-12  |  1KB  |  42 lines

  1.      // examp402.cpp - link with binder.obj
  2.  
  3.      #include <string.h>
  4.      #include <iostream.h>
  5.  
  6.      struct str {
  7.        char *s;
  8.        str(const char *cs = (char *)0)  // default constructor
  9.           { s = (cs? strdup(cs) : (char *)0); }
  10.        str(str& si)                     // copy initialize
  11.             { s = (si.s? strdup(si.s) : si.s); }
  12.        void operator=(str& si)          // assignment
  13.             { delete s; s = (si.s? strdup(si.s) : si.s); }
  14.        void operator=(const char * cs)
  15.             { delete s; s = (cs? strdup(cs) : (char *)0); }
  16.        ~str() { delete s; }             // destructor
  17.      };
  18.  
  19.      ostream& operator<<(ostream& os, str&)
  20.        { return os; }
  21.  
  22.      istream& operator>>(istream& is, str&)
  23.        { return is; }
  24.  
  25.      #include "tbinder.hpp"
  26.      TBINDER(str,StrBdr,StrBdR);
  27.  
  28.      main()
  29.      {
  30.        StrBdr sb(BDR_DDELETE);
  31.  
  32.        sb.ins(new str("line one"));
  33.        str s("Why won't this string appear in the Binder?");
  34.        sb.insNew(&s);
  35.        s = "line two";
  36.        sb.setFlags(BDR_DNEW);
  37.        sb.insNew(&s);
  38.        sb.setCurNode();        // reset current node
  39.        while (sb.next())  cout << ((str *)sb)->s << "\n";
  40.        return 0;
  41.      }
  42.